<template>
  <view class="universal-detail">
    <view class="universal-detail-top">
      <view class="universal-detail-top-time"><text class="universal-detail-top-title">审核</text></view>
    </view>
    <view class="universal-detail-cont">
      <van-form class="universal-detail-form initForm" @submit="onSubmit" :readonly="loading" label-width="130rpx" colon>
        <van-cell-group inset>
          <van-field
            name="checkboxGroup" required label="审核结果"
            :rules="[{ required: true, message: '请选择审核结果' }]"
          >
            <template #input>
              <van-radio-group v-model="form.audit" direction="horizontal">
                <van-radio name="0">通过</van-radio>
                <van-radio name="1">不通过</van-radio>
              </van-radio-group>
            </template>
          </van-field>
          <van-field
            v-model="form.auditResult"
            rows="4" autosize type="textarea"
            show-word-limit maxlength="200"
            label="审核理由"
            placeholder=""
          />
        </van-cell-group>
        <view class="universal-detail-bottom">
          <van-button @click="$emit('cancel')" class="universal-detail-bottom-button universal-detail-bottom-button-cancel" type="default">取消</van-button>
          <van-button 
            class="universal-detail-bottom-button universal-detail-bottom-button-sumbit" type="primary" native-type="submit"
            :loading="loading" loading-text="提交中..."
          >提交</van-button>
        </view>
      </van-form>
    </view>
  </view>
</template>

<script setup>
import dayjs from 'dayjs'
import { ref } from 'vue';
import { apiHiddenTrobleAudit } from '@/api/hiddenTroble';

const form = ref({});
const model = defineModel();
const emit = defineEmits(['confirm']);
const loading = ref(false);

const onSubmit = () => {
  loading.value = true;
  const params = {
    ...form.value,
    troubleId: model.value.troubleId,
    auditor: model.value.auditUser,
    auditUserName: model.value.auditUserName,
  }
  apiHiddenTrobleAudit(params).then(res => {
    loading.value = false;
    emit('confirm');
  })
}
</script>

<style lang="scss" scoped>
@import '@/assets/universal-detail.scss';
</style>